home *** CD-ROM | disk | FTP | other *** search
- unit HtShopC;
-
- //This is an example unit that was inherited from
- //TutParentForm through File|New|<Project>|TutParentForm
- //For inheritance to work, your uses clause must include
- //the units to be inherited from.
-
- // Original code was provided by HREF Tools Corporation, Inc.
- // http://www.href.com
-
- // Amendments (mainly the WebCreditCard1Execute event)
- // by P J Hyde, South Pacific Information Services Ltd
- // http://www.spis.co.nz
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- UTPANFRM, ExtCtrls, StdCtrls, TpLabel, Toolbar, WebMail, WebSock,
- DBTables, DB, WdbSorce, UpdateOk, tpAction, WebTypes, WebIniFL, WebLink,
- WdbLink, WdbScan, WdbGrid, ebutton, TpMemo, WebMemo, DBCtrls, Buttons,
- Grids, DBGrids, ComCtrls, tpStatus, WebCCard;
-
- type
- TfmShopPanel = class(TutParentForm)
- ToolBar: TtpToolBar;
- PageControl1: TPageControl;
- TabSheet3: TTabSheet;
- Image1: TImage;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- TabSheet1: TTabSheet;
- DBGrid1: TDBGrid;
- DBNavigator1: TDBNavigator;
- WebDataGrid1: TWebDataGrid;
- WebActionOrderList: TWebAction;
- WebActionPostLit: TWebAction;
- WebDataSource1: TWebDataSource;
- DataSource1: TDataSource;
- Table1: TTable;
- Table1PartNo: TFloatField;
- Table1VendorNo: TFloatField;
- Table1Description: TStringField;
- Table1OnHand: TFloatField;
- Table1OnOrder: TFloatField;
- Table1Cost: TCurrencyField;
- Table1ListPrice: TCurrencyField;
- Table1Qty: TSmallintField;
- WebActionMailer: TWebAction;
- tpStatusBar1: TtpStatusBar;
- tpToolButton1: TtpToolButton;
- tsEConfig: TTabSheet;
- Label4: TLabel;
- EditEMailFrom: TEdit;
- EditEMailTo: TEdit;
- Label5: TLabel;
- EditMailhost: TEdit;
- Label6: TLabel;
- Label7: TLabel;
- Label8: TLabel;
- EditSubject: TEdit;
- Label9: TLabel;
- EditMailPort: TEdit;
- WebCreditCard1: TWebCreditCard;
- procedure Table1QtyGetText(Sender: TField; var Text: string;
- DisplayText: Boolean);
- procedure WebActionPostLitExecute(Sender: TObject);
- procedure WebActionOrderListExecute(Sender: TObject);
- procedure WebActionMailerExecute(Sender: TObject);
- procedure tpToolButton1Click(Sender: TObject);
- procedure WebCreditCard1Execute(Sender: TObject);
- private
- { Private declarations }
- procedure getOrderList( sList: TStringList );
- procedure ConfigEMail;
- public
- { Public declarations }
- function Init: Boolean; override;
- end;
-
- var
- fmShopPanel: TfmShopPanel;
-
- implementation
-
- {$R *.DFM}
-
- uses
- WebApp, AppUtil, utSpltfm, ucString, whMail;
-
- //------------------------------------------------------------------------------
-
- function TfmShopPanel.Init:Boolean;
- begin
- Result:= inherited Init;
- if not result then
- exit;
- //
- fmWebMail.webmail.subject:=''; // init so that we know to config later.
- //
- {Other required settings:
- twebdatagrid
- datascanoptions all set to true, except refresh and checkboxes
- buttonsWhere above
- controlsWhere none
-
- twebdatasource
- maxOpenDataSets 1 (no cloning)
- displaySets defined in .ini file
-
- TTable
- add fields using Delphi field editor
- add calculated field called Qty, type integer
- }
- end;
-
- //------------------------------------------------------------------------------
- //------------------------------------------------------------------------------
-
- procedure TfmShopPanel.ConfigEMail;
- begin
- {configure email based on values on form. These are saved to the
- href.ini file by the Restorer component.}
- // e-mail settings -- please change to use your own defaults!
- if EditEMailFrom.text='' then EditEMailFrom.text:='someone@theweb.com';
- if EditEMailTo.text='' then EditEMailTo.text:='info@href.com';
- if EditMailHost.text='' then EditMailHost.text:='mail.href.com';
- if EditMailPort.text='' then EditMailPort.text:='25';
- if EditSubject.text='' then EditSubject.text:='** Shop1 Sale';
- //
- with fmWebMail.webmail do begin
- Sender.EMail:=EditEmailFrom.text;
- MailTo.clear;
- MailTo.add(editEMailTo.text);
- MailHost.hostname:=EditMailhost.text;
- MailHost.port:=StrToIntDef(EditMailport.text,25);
- Subject:=EditSubject.text;
- end;
- end;
-
- { ------------------------------------------------------------------------- }
-
- { To see what webhub is doing with your data, add %=chDebugInfo=% to the
- bottom of the homepage and/or confirm pages. That will display some
- key arrays: webserver.dbFields, webserver.FormLiterals and websession.Literals.
-
- The data entered by the surfer into the webdatagrid is posted to the
- dbFields array. We need to jump in and copy that to the Literals array,
- because dbFields is cleared at the end of the page. Since we don't have
- a real table to post to, we are using the Literals array as temporary
- storage. (Yes, you could add a temporary order table and post Qty there.)
- }
- procedure TfmShopPanel.WebActionPostLitExecute(Sender: TObject);
- var
- a1,a2:string;
- i:integer;
- begin
- //WebDataSource1.Qty@1316=35
- with TWebAction(Sender).WebApp do begin
- for i:=0 to pred(WebServer.dbFields.count) do begin
- SplitString(WebServer.dbFields[i],'=',a1,a2);
- if a2<>'' then
- Literal[a1]:=a2; {post single entry to Literals array}
- end;
- end;
- end;
-
- { ------------------------------------------------------------------------- }
-
- { Illusion central:
- Make the table act multi-surfer by defining the calculated field as equal to
- the current surfer's Literals.}
- procedure TfmShopPanel.Table1QtyGetText(Sender: TField; var Text: string;
- DisplayText: Boolean);
- begin
- Text:=getWebApp.Literal['webdatasource1.Qty@'+
- Sender.DataSet.FieldByName('PartNo').asString];
- end;
-
-
- { ------------------------------------------------------------------------- }
- { ------------------------------------------------------------------------- }
-
- {Fill a stringlist with the current order.
- Loop thru the Literals[] array looking for items with @ which come from the
- data entry session.}
- procedure TfmShopPanel.getOrderList( sList: TStringList );
- var
- a1,a2:string;
- i:integer;
- begin
- slist.clear;
- with getWebApp.WebSession do begin
- for i:=0 to pred(Literals.count) do begin
- a1:=LeftOfEqual(Literals[i]);
- if pos( '@', a1 ) > 0 then begin
- //WebDataSource1.Qty@1316=35
- SplitString(Literals[i],'=',a1,a2); // SplitString is in the ucString unit
- slist.add( 'Qty ' + a2 + ' of Product #' + RightOf( '@', a1 ));
- end;
- end;
- end;
- end;
-
-
- { ------------------------------------------------------------------------- }
-
- {this is one way to echo the current order.}
- procedure TfmShopPanel.WebActionOrderListExecute(Sender: TObject);
- var
- sList:TStringList;
- begin
- sList:=nil;
- try
- sList:=TStringList.create;
- getOrderList(slist);
- //send out the order, with a <BR> at end of each line
- TWebAction(Sender).WebApp.WebOutput.SendStringListBR(slist);
- finally
- slist.free;
- end;
- end;
-
- { ------------------------------------------------------------------------- }
-
- { Prepare and send mail message.}
- procedure TfmShopPanel.WebActionMailerExecute(Sender: TObject);
- var
- sList:TStringList;
- begin
- with TWebAction(Sender).WebApp, fmWebMail.webmail do begin
- if subject='' then
- configEMail;
- //
- Sender.Name:=Literal['CustFullName'];
- // fill in the message (Lines property)
- Lines.clear;
- (* original HREF code
- Lines.add( 'CUSTOMER:' );
- Lines.add( Literal['CustFullName'] );
- Lines.add( Literal['CustCity'] );
- replaced by PH with:
- *)
- Lines.addStrings(Webserver.FormLiterals); { get it all in as var=value lines }
-
- Lines.add( '' );
- Lines.add( 'ORDER:' );
- sList:=nil;
- try
- sList:=TStringList.create;
- getOrderList(slist);
- Lines.AddStrings(slist);
- finally
- slist.free;
- end;
- execute; {send the message}
- end;
- end;
-
- { ------------------------------------------------------------------------- }
-
- { fun with tool buttons...}
-
- procedure TfmShopPanel.tpToolButton1Click(Sender: TObject);
- begin
- with DBGrid1 do
- if DataSource=nil then begin
- DataSource:=DataSource1;
- DbNavigator1.DataSource:=DataSource1;
- end
- else begin
- DataSource:=nil;
- DbNavigator1.DataSource:=nil;
- end
- end;
-
-
- procedure TfmShopPanel.WebCreditCard1Execute(Sender: TObject);
- begin
- inherited;
- with WebCreditCard1,WebCreditCard1.WebApp do
- begin
- if CompareText(Command,'CLEAR')=0 then exit;{ No check if clearing }
- (*
- CardNumber := Literal['CardNumber']; { Get surferÆs form input }
- ExpirationDate := Literal['ExpirationDate'];
- *)
- if (not Accept) or { Bad CC number/date }
- (Literal['CardHolderName']='') then { Blank name }
- begin
- Literal['CardProblem']:='Yes'; { Flag the problem }
- WebOutput.send('%=Bounce|confirm=%'); { Bounce back to card entry form}
- end else
- Literal['CardProblem']:=''; { Clear any prior flag }
- end;
- end;
-
- end.
-